< previous page page_45 next page >

Page 45
In the third picture box, ClipControls is set to false, so graphics during Paint events cover all the controls. After drawing the graphics, code in the Paint event handler explicitly executes the text box's Refresh method, so the text box is redrawn. Then, after the Paint event is complete, Visual Basic automatically refreshes the label and image controls so that the graphics lie behind all the controls. If you look closely at the text box, however, you will see that the form's graphics cover parts of the control's border.
While the first picture box takes a little longer to redraw than the others, the difference is usually so small that it may not be worth the added complications. You may want to leave ClipControls true until you are certain you have performance problems and this small improvement is worth the extra effort.
Picture Property
The Picture property of a form, image, or picture box specifies the picture that should be displayed by the object. This picture becomes the background that is displayed whenever all other graphics are erased. For instance, a form's Cls method erases all other graphics from the form so that only the background picture is displayed.
Image Property
The Image property of a form or picture box is a persistent bitmap stored in memory that contains the object's current contents. If you set AutoRedraw to true, Visual Basic uses this bitmap to redraw the object when it is exposed. If you set AutoRedraw to false, the Image property still exists, but Visual Basic does not use it to redraw the object. You must do any necessary redrawing in the object's Paint event procedure.
You can use the Image property to set the value of an object's Picture property. For example, the following code sets the Picture property of one picture box equal to the Image property of another. The first will display as a permanent part of its background whatever the second is currently displaying.
e10a6a0a59f035e870d90cca05b85fce.gif
picTo.Picture = picFrom.Image
Example program ImagePic, shown in Figure 1.27, displays two picture boxes. Click and drag the mouse on either picture box to draw on it. Click the Copy button to copy the left picture box's Image property into the right picture box's Picture property. That makes whatever the left picture box is displaying become the permanent background for the right picture box.
When you click the left Clear button, the left picture box clears. When you click the right Clear button, the right picture box clears to display whatever is stored in its Picture property.
For example, draw on the left picture box and click the Copy button. That copies the picture into the right picture box. Now draw on top of that image in the right picture box. If you now click the right Clear button, the new drawing is erased, leaving the original image from the left picture box.

 
< previous page page_45 next page >